home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / ORPHAN.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  4KB  |  155 lines

  1. // ORPHAN.CPP                                 1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9. #include <time.h>
  10.  
  11. #define PROGRAM "ORPHAN"  // Name of module
  12. /*********************************************************************/
  13.  
  14. typedef struct
  15. {
  16.     char source_directory[120];  /* hold so we can tell when it changes */
  17.     int number_orphans;
  18.     LISTPTR list;
  19. } ORPHAN_INFO;
  20.  
  21. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  22. static void get_files(AU *au, LISTPTR *list)
  23. {
  24.     HANDLE handle;
  25.     char string[80];
  26.  
  27.     for (int fpos = 0 ; fpos < au->flist_pos; fpos++)
  28.     {
  29.         char *file_name = au->flist[fpos];
  30.  
  31.         if (file_name[0] == '\0')
  32.             continue;
  33.  
  34.         if (handle.open(au, file_name, O_RDWR|O_TEXT) != SUCCESS)
  35.         {
  36.             au_printf_error(au, "\nFile Listing File '%s' not found", file_name);
  37.             continue;
  38.         }
  39.         while (get_next_file_name(au, &handle, string, NULL) != EOF)
  40.         {
  41.             list->add(string);
  42.         }
  43.         handle.close();
  44.     }
  45.     return;
  46. }
  47.  
  48. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  49. static BYTE find_file(char *file_name, LISTPTR *list)
  50. {
  51.     LIST *el;
  52.     for (el = list->head; el != NULL; el = el->next)
  53.     {
  54.         if (stricmp(el->data, file_name) == 0)
  55.             return TRUE;
  56.     }
  57.     return FALSE;
  58. }
  59. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  60. static int orphan(AU *au, char *file_name)
  61. {
  62.     ORPHAN_INFO *in = (ORPHAN_INFO *)au->info;
  63.  
  64.     check_for_key();
  65.  
  66.     if (!ok_to_process(au, file_name))
  67.         return FALSE;
  68.  
  69.     if (strcmp(au->source_directory, in->source_directory) != 0)
  70.     {
  71.         in->list.destroy();
  72.         get_files(au, &in->list);
  73.         strcpy(in->source_directory, au->source_directory);
  74.     }
  75.  
  76.     if (!find_file(file_name, &in->list))
  77.     {
  78.         au_printf(au, "@?6Orphan File: @?1%s@?H\n", file_name);
  79.         in->number_orphans++;
  80.     }
  81.     au->number_processed++;
  82.     return 0;
  83. }
  84. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  85. static BYTE parse_comm_line(AU *au, char option, char *, PARSE_TYPE type)
  86. {
  87.     switch (type)
  88.     {
  89.     case PARSE_PARAM_OPTION:
  90.         switch (option)
  91.         {
  92.         case '?':
  93.             au_standard_opt_header(au, "Orphan", NULL);
  94.             exit (0);
  95.         default:
  96.             au_invalid_option(au, PROGRAM, option);
  97.         }
  98.         return TRUE;
  99.     }
  100.     return FALSE;
  101. }
  102. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  103. static void ReadCFGInfo(AU *au, CFG_HANDLE *cfg_handle)
  104. {
  105.     char string[200],
  106.          string2[200],
  107.          string3[200];
  108.  
  109.     for(EVER)
  110.     {
  111.         if (cfg_handle->read_line(au, string)==EOF)
  112.             break;
  113.  
  114.         split_string(string, string2);
  115.         split_string(string, string3);
  116.  
  117.         if (string2[0] == '\0')
  118.             continue;
  119.  
  120.         strcpy(au->curOpt, string2);
  121.         au->curVal = string3;
  122.         switch (toupper(string2[1]) << 8 | toupper(string2[0]))
  123.         {
  124.             case 'BE':                                          // Begin
  125.                 return;
  126.             case 'DO':                                          // Dont_process
  127.                 au->dont_touch.add(string3);
  128.                 break;
  129.             default:
  130.                 cfg_handle->invalid_option(au, string2);
  131.         }
  132.     }
  133. }
  134. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  135. int main_orphan(AU *au, int argc, char *argv[])
  136. {
  137.     ORPHAN_INFO *in;
  138.  
  139.     in = new ORPHAN_INFO;
  140.     memset(in, '\0', sizeof(ORPHAN_INFO));
  141.     au->info = in;
  142.  
  143.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, ReadCFGInfo);
  144.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  145.     process_files(au, orphan);
  146.  
  147.     if (!au->no_extra)
  148.     {
  149.         au_printf_c(au, 15, "\nFiles Processed = %d\n", au->number_processed);
  150.         au_printf_c(au, 15, "\nOrphans Found   = %d\n", in->number_orphans);
  151.     }
  152.     return 0;
  153. }
  154.  
  155.